import React, { Component } from 'react'

export default class Count extends Component {
  state = {
    count: 0
  }
  add = () => {
    // const { count } = this.state
    //对象式的setState
    // this.setState({ count: count + 1 }, () => {
    //   console.log(count)
    // })
    //函数式的setState  可以拿到state和props
    // this.setState((state, props) => {
    //   return {
    //     count: 99
    //   }
    // })
    this.setState(state => ({ count: state.count + 1 }))
  }
  render() {
    return (
      <div>
        <h1>当前求和为：{this.state.count}</h1>
        <button onClick={this.add}>点我加1</button>
      </div>
    )
  }
}
